<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>鼠标事件</title>
    <style>
        .container{
            width: 500px;
            height: 400px;    
            margin:50px auto;
            background: #aef;
        }

        .inner{
            width: 200px;
            height: 150px;
            background: #c56;
        }
    </style>
</head>
<body>
    <div id="root"> </div>

    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>

    <script type="text/babel">
        class App extends React.Component{
            render(){
                return <div className="container" onClick={this.changeBg}>
                        <a href="http://atguigu.com" onClick={this.handleClick}>尚硅谷</a>
                        <div className="inner" onClick={this.maopao}>冒泡</div>
                    </div>
            }

            //外层 div 的点击事件
            changeBg = (e) => {
                //获取事件源
                // console.log(e.target); //
                e.target.style.background = '#0b6'; //绿色
                //默认行为
                console.log('外层');
            }   
            //内层 div 的点击事件
            maopao = (e) => {
                console.log('内层');
                // console.log(e.clientX);
                //阻止冒泡
                // e.stopPropagation();
            }

            //点击 a 链接事件
            handleClick = (e) => {
                //阻止默认行为
                e.preventDefault(); // 一定要使用 e.preventDefault 阻止默认行为. 
            }
        }

        //渲染
        ReactDOM.render(<App />, document.querySelector("#root"));
    </script>
</body>
</html>